package eti.vilas;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Calculate {
	
	
	private List<Abast> abastList;
	Map<String, List<Abast>> abastMap = new HashMap<String, List<Abast>>();
	
	private double fator = 0.7;
	
	
	public Calculate(List<Abast> abastList) 
	{
		this.abastList = abastList;
		recalculaFator();
	}

	public void recalculaFator()
	{
		
		double rendAlcool = 0.0, rendGasol = 0.0;
		
		List<Abast> abastList2 = new ArrayList<Abast>();
		
		for (Abast abast : abastList) 
		{
		   if((abastList2 = abastMap.get(abast.getCombustivel())) != null)
		   {
		      abastList2.add(abast);
		   }
		   else
		   {
		      abastMap.put(abast.getCombustivel(), new ArrayList<Abast>());
		   }
		}
		
		System.out.println(abastMap);
	       
		
		
		
		
		System.out.println("RendAlcool: " + rendAlcool);
		System.out.println("RendGasoli: " + rendGasol);
		
		
		
	}
	
	public boolean decidirCombustivel(double vrGasol, double vrAlcool)
	{
		return (vrAlcool / vrGasol) < fator;
	}
	
	public static void main(String[] args) throws Exception 
	{
		List<Abast> abastList  = new DBConnection("./dbvcombo.db").getAll();
		
		Calculate calculate = new Calculate(abastList);
		System.out.println( calculate.decidirCombustivel(2.508, 0.6999 * 2.508) ? Combustivel.Alcool : Combustivel.Gasolina );
		
	}

}
